package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author LEO
 * @Date 2021年12月11日 17:19
 */
@Api(tags = "商品Sku信息接口")
@RestController
@RequestMapping("admin/product")
public class SkuManagerController {

    @Autowired
    private ManageService manageService;

    //保存skuInfo！
    //	http://api.gmall.com/admin/product/saveSkuInfo
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return  Result.ok();
    }


    //查询skuInfo 列表
    //		http://api.gmall.com/admin/product/list/{page}/{limit}
    @GetMapping("list/{page}/{limit}")
    public Result getSkuInfoList(@PathVariable("page") Long page,
                                 @PathVariable("limit")Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        IPage iPage= manageService.getSkuInfoList(skuInfoPage);
        return Result.ok(iPage);
    }


    //商品的上架
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable("skuId")Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }

    //商品的下架 下架: {is_sale = 0}
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId")Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }

}
